/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ms.jasim.model.event.impl;

import java.util.Collection;

import ms.jasim.model.event.Event;
import ms.jasim.model.event.EventPackage;
import ms.jasim.model.event.EventSet;
import ms.jasim.model.impl.NamedModelObjectImpl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event Set</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.jasim.model.event.impl.EventSetImpl#getEvent <em>Event</em>}</li>
 *   <li>{@link ms.jasim.model.event.impl.EventSetImpl#getMaxBranches <em>Max Branches</em>}</li>
 *   <li>{@link ms.jasim.model.event.impl.EventSetImpl#getMaxCpuTime <em>Max Cpu Time</em>}</li>
 *   <li>{@link ms.jasim.model.event.impl.EventSetImpl#isEnabled <em>Enabled</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EventSetImpl extends NamedModelObjectImpl implements EventSet {
	/**
	 * The cached value of the '{@link #getEvent() <em>Event</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEvent()
	 * @generated
	 * @ordered
	 */
	protected EList<Event> event;

	/**
	 * The default value of the '{@link #getMaxBranches() <em>Max Branches</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxBranches()
	 * @generated
	 * @ordered
	 */
	protected static final int MAX_BRANCHES_EDEFAULT = 1;
	/**
	 * The cached value of the '{@link #getMaxBranches() <em>Max Branches</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxBranches()
	 * @generated
	 * @ordered
	 */
	protected int maxBranches = MAX_BRANCHES_EDEFAULT;
	/**
	 * The default value of the '{@link #getMaxCpuTime() <em>Max Cpu Time</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxCpuTime()
	 * @generated
	 * @ordered
	 */
	protected static final int MAX_CPU_TIME_EDEFAULT = 999;
	/**
	 * The cached value of the '{@link #getMaxCpuTime() <em>Max Cpu Time</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxCpuTime()
	 * @generated
	 * @ordered
	 */
	protected int maxCpuTime = MAX_CPU_TIME_EDEFAULT;

	/**
	 * The default value of the '{@link #isEnabled() <em>Enabled</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isEnabled()
	 * @generated
	 * @ordered
	 */
	protected static final boolean ENABLED_EDEFAULT = true;

	/**
	 * The cached value of the '{@link #isEnabled() <em>Enabled</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isEnabled()
	 * @generated
	 * @ordered
	 */
	protected boolean enabled = ENABLED_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EventSetImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return EventPackage.Literals.EVENT_SET;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Event> getEvent() {
		if (event == null) {
			event = new EObjectContainmentEList<Event>(Event.class, this, EventPackage.EVENT_SET__EVENT);
		}
		return event;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMaxBranches() {
		return maxBranches;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaxBranches(int newMaxBranches) {
		int oldMaxBranches = maxBranches;
		maxBranches = newMaxBranches;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EventPackage.EVENT_SET__MAX_BRANCHES, oldMaxBranches, maxBranches));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMaxCpuTime() {
		return maxCpuTime;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaxCpuTime(int newMaxCpuTime) {
		int oldMaxCpuTime = maxCpuTime;
		maxCpuTime = newMaxCpuTime;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EventPackage.EVENT_SET__MAX_CPU_TIME, oldMaxCpuTime, maxCpuTime));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isEnabled() {
		return enabled;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEnabled(boolean newEnabled) {
		boolean oldEnabled = enabled;
		enabled = newEnabled;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EventPackage.EVENT_SET__ENABLED, oldEnabled, enabled));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EventPackage.EVENT_SET__EVENT:
				return ((InternalEList<?>)getEvent()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case EventPackage.EVENT_SET__EVENT:
				return getEvent();
			case EventPackage.EVENT_SET__MAX_BRANCHES:
				return getMaxBranches();
			case EventPackage.EVENT_SET__MAX_CPU_TIME:
				return getMaxCpuTime();
			case EventPackage.EVENT_SET__ENABLED:
				return isEnabled();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case EventPackage.EVENT_SET__EVENT:
				getEvent().clear();
				getEvent().addAll((Collection<? extends Event>)newValue);
				return;
			case EventPackage.EVENT_SET__MAX_BRANCHES:
				setMaxBranches((Integer)newValue);
				return;
			case EventPackage.EVENT_SET__MAX_CPU_TIME:
				setMaxCpuTime((Integer)newValue);
				return;
			case EventPackage.EVENT_SET__ENABLED:
				setEnabled((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case EventPackage.EVENT_SET__EVENT:
				getEvent().clear();
				return;
			case EventPackage.EVENT_SET__MAX_BRANCHES:
				setMaxBranches(MAX_BRANCHES_EDEFAULT);
				return;
			case EventPackage.EVENT_SET__MAX_CPU_TIME:
				setMaxCpuTime(MAX_CPU_TIME_EDEFAULT);
				return;
			case EventPackage.EVENT_SET__ENABLED:
				setEnabled(ENABLED_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case EventPackage.EVENT_SET__EVENT:
				return event != null && !event.isEmpty();
			case EventPackage.EVENT_SET__MAX_BRANCHES:
				return maxBranches != MAX_BRANCHES_EDEFAULT;
			case EventPackage.EVENT_SET__MAX_CPU_TIME:
				return maxCpuTime != MAX_CPU_TIME_EDEFAULT;
			case EventPackage.EVENT_SET__ENABLED:
				return enabled != ENABLED_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (MaxBranches: ");
		result.append(maxBranches);
		result.append(", MaxCpuTime: ");
		result.append(maxCpuTime);
		result.append(", Enabled: ");
		result.append(enabled);
		result.append(')');
		return result.toString();
	}

} //EventSetImpl
